//导入共享数据包
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'

// custom-tab-bar/index.js
Component({

    //共享数据相关配置
    options: {
        styleIsolation: 'shared'
    },

    behaviors: [storeBindingsBehavior],

    //引入需要的共享数据
    storeBindings: {
        store,
        fields: {
            active: 'activeTabBarIndex'
        },
        actions: {
            updateActiveTabBarIndex: 'updateActiveTabBarIndex'
        }
    },

    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {

        //tabBar具体项列表
        "list": [
            {
              "pagePath": "/pages/mirror/mirror",
              "text": "害虫识别",
              "icon": "/images/mirror.png",
          },
          {
              "pagePath": "/pages/user/user",
              "text": "用户",
              "icon": "/images/user.png",
          }
        ]
    },

    /**
     * 组件的方法列表
     */
    methods: {

        //当tabBar页面改变时，触发方法
        onChange(event) {
            console.log(event)
            console.log(this.data.list[event.detail].pagePath)
            // event.detail 的值为当前选中项的索引
            this.updateActiveTabBarIndex(event.detail)
            //页面跳转
            wx.switchTab({
              url: this.data.list[event.detail].pagePath,
            })
          }
    }
})